package com.springboot.controller;

import com.springboot.model.AssistantListFormKey;
import com.springboot.model.UserLoginForm;
import com.springboot.service.DoctorDeleteAssistantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 本控制台用于医生在助理列表中删除助理
 */
@Controller
public class DoctorDeleteAssistantController {
    @Autowired
    DoctorDeleteAssistantService doctorDeleteAssistantService;
    /**
     * 医生在助理列表界面删除助理
     */
    @CrossOrigin
    @RequestMapping(value = "/deleteAssistantServlet")
    public @ResponseBody
    String doctorDeleteAssistant(@RequestParam("doctorID") String doctorTel,
                                 @RequestParam("assistantTel") String assistantTel){
        System.out.println("医生删除助理");
        try {
            UserLoginForm doctor=doctorDeleteAssistantService.findUserByTel(doctorTel);
            UserLoginForm assistant=doctorDeleteAssistantService.findUserByTel(assistantTel);
            int doctorId=doctor.getUserId();
            int assistantId=assistant.getUserId();
            AssistantListFormKey assistantListFormKey=new AssistantListFormKey();
            assistantListFormKey.setDoctorId(doctorId);
            assistantListFormKey.setAssistantId(assistantId);
            doctorDeleteAssistantService.deleteRecord(assistantListFormKey);
            return "True";
        } catch (Exception e) {
            return "False";
        }
    }
}